﻿using System;
using System.Data;

namespace DatabaseService
{
    /// <summary>
    /// sysbase转码抽象基类
    /// </summary>
    public abstract class BaseCharset
    {
        /// <summary>
        /// 从数据库取出转码
        /// </summary>
        /// <param name="strSource"></param>
        /// <returns></returns>
        public abstract string getFromDatabase(string strSource);

        /// <summary>
        /// 转码到数据库使用
        /// </summary>
        /// <param name="strSource"></param>
        /// <returns></returns>
        public abstract string insertToDatabase(string strSource);

        /// <summary>
        /// table数据转码
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public DataTable getDataTableFromDatabase(DataTable table)
        {
            for (int i = 0; i < table.Rows.Count; i++)
                for (int j = 0; j < table.Columns.Count; j++)
                    if (table.Rows[i][j] is String && table.Rows[i][j].ToString() != "")
                        table.Rows[i][j] = getFromDatabase(table.Rows[i][j].ToString());
            return table;
        }
    }
}
